<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;


class Facilitator extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'facilitator';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text',
        // 'status_text',
        // 'is_open_text',
        'is_public_text'
    ];
    

    
    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
    }

    // public function getStatusList()
    // {
    //     return ['0' => __('Status 0'), '1' => __('Status 1')];
    // }

    // public function getIsOpenList()
    // {
    //     return ['0' => __('Is_open 0'), '1' => __('Is_open 1')];
    // }

    public function getIsPublicList()
    {
        return ['0' => __('Is_public 0'), '1' => __('Is_public 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    // public function getStatusTextAttr($value, $data)
    // {
    //     $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
    //     $list = $this->getStatusList();
    //     return isset($list[$value]) ? $list[$value] : '';
    // }


    // public function getIsOpenTextAttr($value, $data)
    // {
    //     $value = $value ? $value : (isset($data['is_open']) ? $data['is_open'] : '');
    //     $list = $this->getIsOpenList();
    //     return isset($list[$value]) ? $list[$value] : '';
    // }


    public function getIsPublicTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_public']) ? $data['is_public'] : '');
        $list = $this->getIsPublicList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function admin()
    {
        return $this->belongsTo('Admin', 'serve_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function deladmin()
    {
        return $this->belongsTo('Admin', 'delete_admin', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function brand()
    {
        return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function source()
    {
        return $this->belongsTo('Type', 'source', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function stage()
    {
        return $this->belongsTo('Type', 'stage', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function intention()
    {
        return $this->belongsTo('Type', 'intention', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
